/**
 * 
 */
package org.vsg.stock.core.algorithm;

import java.util.List;

/**
 * 
 * 
 * @author Bill Vison
 *
 */
public abstract class AbstractSortCalculator<S extends Sortable> {
	
	public enum SortOrder {
		ASC , DESC
	}
	
	/**
	 * calculate the sort list
	 */
	abstract void calculate();
	
	/**
	 * the list for sorting calculdate
	 */
	private List<S> needSortList; 
	
	public List<S> getSortList() {
		return needSortList;
	}

	public void setSortList(List<S> sortList) {
		this.needSortList = sortList;
	}
	/**
	 * defind sort order handle 
	 */
	private SortOrder defaultOrder = SortOrder.ASC;
	
	protected void setSortOrder(SortOrder order) {
		defaultOrder = order;
	}
	
	protected SortOrder getSortOrder() {
		return defaultOrder;
	}
	
	protected void swap(List<Sortable> sortList  , int i , int j ) {
		
		Sortable currData = sortList.get(i);
		Sortable preData = sortList.get(j);
		
		sortList.set( i , preData);
		sortList.set( j , currData);
	}	
	
}
